<!-- file reminder -->
<script> 
	
	$(function(){
		/* REMOVE DUPLICATE ID */
		var ids = [];
		$('*').each(function() {
			if (this.id && this.id !== '') {
				if (ids[this.id]) {
					$(this).remove();
				} else {
					ids[this.id] = this
				}
			}
		});
		
		$.fn.fmatter.jenisProyekFormat = function(cellval, opts) {
			switch (cellval){
				<?php foreach($data_m_proyek_jenis as $k=>$value )
					echo " case '".$k."' : return '".$value."' ; break;";
				?>
				default : return cellval;
			}
		};
		
		$.fn.fmatter.sumberDanaFormat = function(cellval, opts) {
			switch (cellval){
				<?php foreach($data_proyek_sumberdana as $k=>$value )
					echo " case '".$k."' : return '".$value."' ; break;";
				?>
				default : return cellval;
			}
		};
		
		$.fn.fmatter.jenisKontrakFormat = function(cellval, opts) {
			switch (cellval){
				<?php foreach($data_proyek_jeniskontrak as $k=>$value )
					echo " case '".$k."' : return '".$value."' ; break;";
				?>
				default : return cellval;
			}
		};
		$.fn.serializeObject = function()
		{
		   var o = {};
		   var a = this.serializeArray();
		   $.each(a, function() {
			   if (o[this.name]) {
				   if (!o[this.name].push) {
					   o[this.name] = [o[this.name]];
				   }
				   o[this.name].push(this.value || '');
			   } else {
				   o[this.name] = this.value || '';
			   }
		   });
		   return o;
		};
		
		/* declarisasi */
		
		btndetail_proyek = $("#btn-detail-proyek");
		btndetail_proyek2 = $("#btn-detail2-proyek");
		grid_proyek = $("#grid-proyek");
		grid_proyek2 = $("#grid-proyek2");
		
		/* method started */
		
		$( "input[type=submit],input[type=button],input[type=reset], button" ).button();

		/* make component */
		
		grid_proyek.jqGrid({ 
			ajaxGridOptions : {type:"POST"},
			serializeGridData : function(postdata) {return postdata; },
			postData : {task : 'LIST1'},
            url: 'c_reminder',
			datatype: "json", 
			colNames:[
				'Tgl Serah Terima I',
				'Kode',
				'Nama Proyek',
				'Tgl Serah Terima II',
				'Cabang',
				'PM',
				'Jenis Proyek',
				'Tahun Mulai',
				'NK Awal',
				'NK Add',
				'NK Akhir',
				'Contact Person',
				'Jenis Kontruksi',
				'Sumber Dana',
				'Jenis Kontrak',
				'Jaminan Pelaksanaan',
				'Jaminan Penawaran',
				'Retensi',
				'Denda',
				'Cara Pembayaran',
				'Uang Muka',
				'Jngk. Wkt. Pembayaran Sertifikasi',
				'Jngk. Wkt. Pembayaran',
				'Cabang_id','proyek_id'],
			colModel:[
				{ name: 'proyek_tglserahterima1'  ,index: 'proyek_tglserahterima1', frozen : true , search : true, formatter : 'date', formatoptions : {newformat : 'd-m-Y'} },
				{ name: 'proyek_kode'  ,index: 'proyek_kode' , search : true, frozen : true},
				{ name: 'proyek_nama'  ,index: 'proyek_nama' , search : true, frozen : true},
				{ name: 'proyek_tglserahterima2'  ,index: 'proyek_tglserahterima2' , search : true, formatter : 'date', formatoptions : {newformat : 'd-m-Y'} },
				{ name: 'cabang_nama'  ,index: 'cabang_nama' , search : true},
				{ name: 'proyek_pm'  ,index: 'proyek_pm' , search : true},
				{ name: 'proyek_jenis'  ,index: 'proyek_jenis' , search : true,  formatter : 'jenisProyekFormat'},
				{ name: 'proyek_tahunmulai'  ,index: 'proyek_tahunmulai' , search : true},
				{ name: 'proyek_nkawal'  ,index: 'proyek_nkawal' , align : "right", search : true, formatter : 'currency'},
				{ name: 'proyek_nkadd'  ,index: 'proyek_nkadd' , align : "right", search : true, formatter : 'currency'},
				{ name: 'proyek_nkakhir'  ,index: 'proyek_nkakhir' , align : "right", search : true , formatter : 'currency'},
				{ name: 'proyek_cp'  ,index: 'proyek_cp' , search : true},
				{ name: 'proyek_kontruksijenis'  ,index: 'proyek_kontruksijenis' , search : true},
				{ name: 'proyek_sumberdana'  ,index: 'proyek_sumberdana' , search : true, formatter :'sumberDanaFormat'},
				{ name: 'proyek_jeniskontrak'  ,index: 'proyek_jeniskontrak' , search : true,  formatter : 'jenisKontrakFormat'},
				{ name: 'proyek_jaminanpelaksanaan'  ,index: 'proyek_jaminanpelaksanaan' , search : true},
				{ name: 'proyek_jaminanpenawaran'  ,index: 'proyek_jaminanpenawaran' , search : true},
				{ name: 'proyek_retensi'  ,index: 'proyek_retensi' , search : true},
				{ name: 'proyek_denda'  ,index: 'proyek_denda' ,  align : "right",search : true},
				{ name: 'proyek_carapembayaran'  ,index: 'proyek_carapembayaran' , search : true},
				{ name: 'proyek_uangmuka'  ,index: 'proyek_uangmuka' ,  align : "right",search : true},
				{ name: 'proyek_jangkawaktusetifikasi'  ,index: 'proyek_jangkawaktusetifikasi' , search : true},
				{ name: 'proyek_jangkawaktupembayaran'  ,index: 'proyek_jangkawaktupembayaran' , search : true},
				{ name: 'm_cabang_id'  ,index: 'm_cabang_id'  , hidden : true},
				{ name: 'proyek_id'  ,index: 'proyek_id',key: true, hidden: true , search : false}
			],
			width: '900',
			height: 'auto', 
			shrinkToFit: false,
			rowNum:10, 
			rowList:[10,20,30], 
			pager: '#pgrid-proyek', 
			sortname: 'proyek_id', 
			viewrecords: true, 
			sortorder: "desc",
			caption:"" 
		}); 
		grid_proyek.jqGrid('navGrid','#pgrid-proyek',{edit:false,add:false,del:false,search:false});
		// grid_proyek.jqGrid('filterToolbar',{});
	 	grid_proyek.jqGrid('setFrozenColumns');
		
		
		grid_proyek2.jqGrid({ 
			ajaxGridOptions : {type:"POST"},
			serializeGridData : function(postdata) {return postdata; },
			postData : {task : 'LIST2'},
            url: 'c_reminder',
			datatype: "json", 
			colNames:[
				'Tgl Serah Terima II',
				'Kode',
				'Nama Proyek',
				'Tgl Serah Terima I',
				'Cabang',
				'PM',
				'Jenis Proyek',
				'Tahun Mulai',
				'NK Awal',
				'NK Add',
				'NK Akhir',
				'Contact Person',
				'Jenis Kontruksi',
				'Sumber Dana',
				'Jenis Kontrak',
				'Jaminan Pelaksanaan',
				'Jaminan Penawaran',
				'Retensi',
				'Denda',
				'Cara Pembayaran',
				'Uang Muka',
				'Jngk. Wkt. Pembayaran Sertifikasi',
				'Jngk. Wkt. Pembayaran',
				'Cabang_id','proyek_id'],
			colModel:[
				{ name: 'proyek_tglserahterima2'  ,index: 'proyek_tglserahterima2', frozen : true , search : true, formatter : 'date', formatoptions : {newformat : 'd-m-Y'} },
				{ name: 'proyek_kode'  ,index: 'proyek_kode' , search : true, frozen : true},
				{ name: 'proyek_nama'  ,index: 'proyek_nama' , search : true, frozen : true},
				{ name: 'proyek_tglserahterima1'  ,index: 'proyek_tglserahterima1' , search : true, formatter : 'date', formatoptions : {newformat : 'd-m-Y'} },
				{ name: 'cabang_nama'  ,index: 'cabang_nama' , search : true},
				{ name: 'proyek_pm'  ,index: 'proyek_pm' , search : true},
				{ name: 'proyek_jenis'  ,index: 'proyek_jenis' , search : true,  formatter : 'jenisProyekFormat'},
				{ name: 'proyek_tahunmulai'  ,index: 'proyek_tahunmulai' , search : true},
				{ name: 'proyek_nkawal'  ,index: 'proyek_nkawal' , align : "right", search : true, formatter : 'currency'},
				{ name: 'proyek_nkadd'  ,index: 'proyek_nkadd' , align : "right", search : true, formatter : 'currency'},
				{ name: 'proyek_nkakhir'  ,index: 'proyek_nkakhir' , align : "right", search : true , formatter : 'currency'},
				{ name: 'proyek_cp'  ,index: 'proyek_cp' , search : true},
				{ name: 'proyek_kontruksijenis'  ,index: 'proyek_kontruksijenis' , search : true},
				{ name: 'proyek_sumberdana'  ,index: 'proyek_sumberdana' , search : true, formatter :'sumberDanaFormat'},
				{ name: 'proyek_jeniskontrak'  ,index: 'proyek_jeniskontrak' , search : true,  formatter : 'jenisKontrakFormat'},
				{ name: 'proyek_jaminanpelaksanaan'  ,index: 'proyek_jaminanpelaksanaan' , search : true},
				{ name: 'proyek_jaminanpenawaran'  ,index: 'proyek_jaminanpenawaran' , search : true},
				{ name: 'proyek_retensi'  ,index: 'proyek_retensi' , search : true},
				{ name: 'proyek_denda'  ,index: 'proyek_denda' ,  align : "right",search : true},
				{ name: 'proyek_carapembayaran'  ,index: 'proyek_carapembayaran' , search : true},
				{ name: 'proyek_uangmuka'  ,index: 'proyek_uangmuka' ,  align : "right",search : true},
				{ name: 'proyek_jangkawaktusetifikasi'  ,index: 'proyek_jangkawaktusetifikasi' , search : true},
				{ name: 'proyek_jangkawaktupembayaran'  ,index: 'proyek_jangkawaktupembayaran' , search : true},
				{ name: 'm_cabang_id'  ,index: 'm_cabang_id'  , hidden : true},
				{ name: 'proyek_id'  ,index: 'proyek_id',key: true, hidden: true , search : false}
			],
			width: '900',
			height: 'auto', 
			shrinkToFit: false,
			rowNum:10, 
			rowList:[10,20,30], 
			pager: '#pgrid-proyek2', 
			sortname: 'proyek_id', 
			viewrecords: true, 
			sortorder: "desc",
			caption:"" 
		}); 
		grid_proyek2.jqGrid('navGrid','#pgrid-proyek2',{edit:false,add:false,del:false,search:false});
		// grid_proyek2.jqGrid('filterToolbar',{});
	 	grid_proyek2.jqGrid('setFrozenColumns');
		
		/* event */
		
		btndetail_proyek.click(function(){
			id = grid_proyek.getGridParam("selrow");
			if (id == null){
				alert("Silakan pilih proyek yang akan dilihat detailnya !");
			}else{
				$.ajax({
					type: 'POST',
					url: 'c_proyek',
					data: {proyek_id: data.id, task : 'DETAIL', proyek_id : id },
					success: function(response){
						if(response==1){
							window.open("../print/detail.html","","width=500,height=700,scrollbars=yes");
						}
					}
				});
			}
		});
		
		
		btndetail_proyek2.click(function(){
			id = grid_proyek2.getGridParam("selrow");
			if (id == null){
				alert("Silakan pilih proyek yang akan dilihat detailnya !");
			}else{
				$.ajax({
					type: 'POST',
					url: 'c_proyek',
					data: {proyek_id: data.id, task : 'DETAIL', proyek_id : id },
					success: function(response){
						if(response==1){
							window.open("../print/detail.html","","width=500,height=700,scrollbars=yes");
						}
					}
				});
			}
		});
		
	});
</script>
	<h3>Tanggal Serah Terima Pertama</h3>
	<table id="grid-proyek" class="table table-striped table-bordered" ></table>
	<div id="pgrid-proyek"></div>
	<br />
	<button id="btn-detail-proyek">Detail</button>
	
	<p>&nbsp;</p>
	<h3>Tanggal Serah Terima Kedua</h3>
	<table id="grid-proyek2" class="table table-striped table-bordered" ></table>
	<div id="pgrid-proyek2"></div>
	<br />
	<button id="btn-detail2-proyek">Detail</button>